﻿using System;
using System.Data;
using System.Drawing;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using HiauPdm.Bll;
using HiauPdm.Web;

namespace HiauPdm.Web
{
    public partial class CpSjhDj : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                TextDh.Attributes["readonly"] = "readonly";
                TextLb.Attributes["readonly"] = "readonly";
                BtnXzdh.OnClientClick = "if(ShowDialog('CplbXz.aspx',850,600)!=null){document.getElementById('" + TextDh.ClientID + "').value=returnLbbh;document.getElementById('" + TextLb.ClientID + "').value=returnLbmc;}document.getElementById('" + TextMc.ClientID + "').select();return false;";
                BtnAdd.OnClientClick = "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(BtnAdd, null) + ";return false;";
                BindData();
                TextMc.Focus();
            }
        }

        private void BindData()
        {
            DataSet ds = BCpSjBj.GetCpSjhDjByDjr(IsAccess("编辑他人的产品设计") ? string.Empty : (string)Session["RealName"]);
            if ((ds == null) || (ds.Tables[0].Rows.Count <= 0))
            {
                PanelList.InnerHtml = "<table cellspacing='0' cellpadding='0' border='0' style='border-style:none;border-collapse:collapse;width:832px;text-align:center;'><tr><td>[未登记新的产品设计代号]</td></tr></table>";
            }
            else
            {
                GridCpSj.DataSource = ds;
                GridCpSj.DataBind();
                if (!IsAccess("CpSjBj.aspx"))
                {
                    for (int i = 0; i < GridCpSj.Rows.Count; i++)
                    {
                        GridCpSj.Rows[i].Cells[7].Controls[1].Visible = false;
                    }
                }
            }
        }

        protected void BtnAdd_Click(object sender, EventArgs e)
        {
            if (!ShowErr(BCpSjBj.SaveCpSjh(TextDh.Text, TextLb.Text, TextMc.Text, TextGgxh.Text, TextDw.Text, TextBz.Text, (string)Session["RealName"])))
            {
                Response.Redirect(Request.Url.PathAndQuery);
            }
        }

        protected void GridCpSj_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (!ShowErr(BCpSjBj.DelCpSjh((int)GridCpSj.DataKeys[e.RowIndex].Value)))
            {
                Response.Redirect(Request.Url.PathAndQuery);
            }
        }
    }
}